1. Field of the Invention
The present invention relates generally to computer software. More particularly, the present invention relates to improving the allocation of memory to local objects and the reclaiming of the memory allocated to the local objects,
2. Discussion of Related Art
The JAVA(trademark) Virtual Machine does not provide explicit methods to release memory allocated to objects which are no longer in use. Instead, the Java runtime environment relies upon garbage collection to identify and reclaim objects no longer in use automatically. Garbage collection relies upon the observation that a previously allocated memory location that is no longer referenced by any pointers is no longer accessible to the application and is therefore reclaimable. The role of the garbage collector is to identify and recycle these inaccessible allocated memory chunks.
Two commonly used garbage collection methods include xe2x80x9cmark and sweepxe2x80x9d garbage collection and copying garbage collection. Mark and sweep garbage collection is typically performed in two passes. During the first pass, each object that is not referenced by any objects is marked for deletion. During the second pass, the memory for each object that is not marked is reclaimed.
During copying garbage collection, all objects that are referenced by one or more objects are copied while those objects that are not referenced by any other objects are not copied. Once copied, the memory for the original objects may then be reclaimed.
Most garbage collection optimizations address specific garbage collection algorithms allowing faster and better allocation of space for new objects and the freeing of space allocated to dead objects (i.e., objects that are no longer referenced). In other words, other such garbage collection optimization schemes address issues related to how to allocate and collect objects. More particularly, these garbage collection optimization schemes treat all objects equally, rather than treating each type of object differently.
There are generally two types or classes of objects. The first type of object is a xe2x80x9clocalxe2x80x9d object. Local objects are those objects created during Java method execution and not referenced after the method execution completes. In other words, these local objects operate as temporary objects, since they are not referenced outside the scope of the method. All other objects belong to the second class, or are xe2x80x9cnon-localxe2x80x9d objects. Previously implemented systems and garbage collection optimization schemes fail to treat these two types of objects differently.
In view of the above, it would be desirable if memory could be reclaimed for objects no longer referenced in an efficient manner. Moreover, it would be desirable if memory could be reclaimed through the identification of different types of objects. More specifically, it would be beneficial if the differences between local and non-local objects could be applied to improve the efficiency of the reclaiming of memory occupied by local objects. In addition, it would be beneficial if memory no longer in use could be reclaimed without performing garbage collection.
The present invention enables memory to be reclaimed for objects no longer referenced. This is accomplished, in part, through the identification of particular types of objects (e.g., local objects). In this manner, memory associated with various types of objects may be reclaimed when no longer in use.
In accordance with one aspect of the present invention, specific types of objects are identified to enable memory associated with the identified objects to be reclaimed. Methods include identifying one or more objects of a first object type, obtaining one or more addresses of source code adapted for creating the one or more objects identified as the first object type when the source code is executed, and performing class file generation such that the one or more addresses are stored in a data structure in one or more class files.
In accordance with another aspect of the present invention, methods and apparatus for executing a method to enable memory associated with objects not referenced external to the executed method to be reclaimed upon completion of execution of the method. Methods include obtaining a data structure including one or more addresses of source code that creates local objects, obtaining next source code in the method, and determining whether an address of the obtained next source code is in the data structure. When the address of the obtained next source code is in the data structure including one or more addresses of source code that creates local objects, a local object is created on a local heap of memory using the source code associated with the address such that local objects are stored in memory separately from non-local objects.